#include <REGX52.H>
#include <INTRINS.H>
#include "time0.h"
#include "Nixie.h"
#include "key.h"
#include "delay.h"

sbit Moto=P1^3;
unsigned char Compare = 0;
unsigned char KeyNum;

void main()
{
	unsigned char Speed = 0;
	Timer0_Init();		//定时器初始化
	
	Nixie(1,0);
	while(1)
	{
		KeyNum = Key();
		if(KeyNum)
		{
			if(KeyNum == 1)
			{
				Compare = 50;
				Speed = 1;
			}
			else if(KeyNum == 2)
			{
				Compare = 75;
				Speed = 2;
			}
			else if(KeyNum == 3)
			{
				Nixie(1,3);
				Compare = 100;
				Speed = 3;
			}
			else if(KeyNum == 4)
			{
				Compare = 0;
				Speed = 0;
			}
		}
		Nixie(1,Speed);
	}
}

/**
  * @brief  定时器0中断处理函数模版
  * @param  无
  * @retval 无
  */
void Timer0_Routine(void) interrupt 1
{
	static unsigned int count = 0;
	
	count++;
	if(count < PWM_Threshold){
		Moto = 1;				//ULN2003输出低电平，电机转动
	}
	else{
		Moto = 0;				//ULN2003输出高电平，电机停止
	}
	if(count >= 100)
		count = 0;
	
	//定时器溢出之后需要重新装载
	TH0 = 0xFF;					//50微秒@11.0592MHz
	TL0 = 0xD2; 				//定时器装载周期为50微秒
}